<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<link rel="stylesheet" type="text/css" href="./scripts/cleditor/jquery.cleditor.css" />
<script type="text/javascript" src="./scripts/cleditor/jquery.min.js"></script>
<script type="text/javascript" src="./scripts/cleditor/jquery.cleditor.min.js"></script>

<c:set var="isPageSubmitted" value="${isPageSubmitted}" scope="request"/>
<c:set var="accessDenied" value="${accessDenied}" scope="request"/>
<% 
boolean isPageSubmitted = request.getAttribute("isPageSubmitted") != null ? 
						(Boolean)request.getAttribute("isPageSubmitted") : false;
boolean accessDenied = request.getAttribute("accessDenied") != null ?
						(Boolean)request.getAttribute("accessDenied") : false;

if (accessDenied){
%>
<table cellpadding="3" cellspacing="1" border="0" width="100%" height=500px>
	<tr class="row-title"><td class="header21" align=left>
	</td></tr>
	<tr><td class="intd" align="center" valign="top">

		<table cellpadding="0" cellspacing="1" border="0" bgcolor="#4682B4"  width="350"><tr><td>
		<table cellpadding="2" cellspacing="0" border="0" width="350" bgcolor="#DBEAF5">
			<tr><td colspan="2">&nbsp;</td></tr>
			<tr><td align="center">
				<font class="button"><c:out escapeXml="false" value="${message}"/></font>
			</td></tr>
			<tr><td colspan="2">&nbsp;</td></tr>
			</table>
		</table><br>

	</td></tr>
</table>
<%
	return;
}

if (!isPageSubmitted){
%>

<script type="text/javascript">
	$(document).ready(function() {
    $("#post_content").cleditor({width:600, height:400, useCSS:true})[0].focus();});
</script>
<script type="text/javascript">
   	var _gaq = _gaq || [];
   	_gaq.push(['_setAccount', 'UA-18352523-1']);
   	_gaq.push(['_trackPageview']);
	(function() {
     	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
     	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
   	})();
</script>
<script type="text/javascript">
	function setFocus(){
		document.input_form.post_title.focus();
	}
</script>

<form action="./view.m?page=post-input" method="post" name="input_form">
<table cellpadding="3" cellspacing="1" border="0" width="100%" height=500px>
	<tr class="row-title"><td class="header21" align=left><b>add post</b></td></tr>
	<tr><td valign="top">
		<table border="0" width=100% cellpadding="2" cellspacing="1">
		<tr class="row-title"><td align=left class="post-title">
			&nbsp;title:
		</td></tr>
		<tr><td align=left>
			<input type="text" id="post_title" name="post_title" style="width:600px; border:1" />
		</td></tr>
		<tr><td align=left>
			<table width=100% cellpadding="2" cellspacing="1" border="0">
				<tr class="row-title"><td class="post-title" align=left width=50%>&nbsp;category:</td>
				<td class="post-title" align=left width=50%>&nbsp;author:</td></tr>
				<tr><td>
					
					<select name="post_cat" id="post_cat" style="width: 250px;" >
					<c:forEach items="${cats}" var="cat">
						<option value="<c:out value="${cat.id}"/>" selected="selected"><c:out value="${cat.name}"/></option>	
					</c:forEach>	
					</select>
					
				</td><td>
					<input type="text" disabled="disabled" style="width: 250px;" value="<c:out value="${author.fullname}"/>"/>
					<input type="hidden" name="post_author" id="post_author" value="<c:out value="${author.id}"/>" />
				</td></tr>
			</table>
		</td></tr>
		<tr class="row-title"><td align=left class="post-title">
			&nbsp;summary:
		</td></tr>
		<tr><td>
			<textarea rows="5" cols="120" id="post_summary" name="post_summary"></textarea>
		</td></tr>
		<tr class="row-title"><td align=left class="post-title">
			&nbsp;quickview image url (note: image will be resized to fit the main view):
		</td></tr>
		<tr><td>
			<input type="text" id="post_imgurl" name="post_imgurl" style="width:600px;" /> 
		</td></tr>
		<tr class="row-title"><td align=left class="post-title">
			&nbsp;content:
		</td></tr>
		<tr><td>
			<textarea rows="20" cols="120" id="post_content" name="post_content" ></textarea> 
		</td></tr>
		<tr><td>
			<input class="button" type="reset" name="clear" value="clear">&nbsp;
			<input class="button" type="submit" name="submit" value="submit">
		</td></tr>
		</table>
	</td></tr>
</table>
</form>

<% }else{ %>

<table cellpadding="3" cellspacing="1" border="0" width="100%" height=500px>
	<tr class="row-title"><td class="header21" align=left><b>post result</b></td></tr>
	<tr><td valign="top">
		<table border="0" width=100% cellpadding="2" cellspacing="1">
		<tr class="row-title"><td align=left class="post-title">
			&nbsp;<b>result:</b>
		</td></tr>
		<tr><td align=left>
			<c:out escapeXml="false" value="${message}"></c:out>
		</td></tr>
		<tr class="row-title"><td align=left class="post-title">
			&nbsp;<b>next actions:</b>
		</td></tr>
		<tr><td align=left>
			<ul>
			<li><a href="./view.m">back to posts</a><br>
			<li><a href="./view.m?page=post-input">add more post</a>
			</ul>
		</td></tr>
		</table>
	</td></tr>
</table>
<% }%>